#include <iostream>
#include <string>
#include "../head/student.h"
#include "../head/SortTestHelper.h"

using namespace std;

template<typename T> void selectionSort(T arr[],int n);
void test();

int main(){
	const int arrSize = 10;

	int arr[10] = {3,56,1,7,21,9,6,5,1,8};
	// float arr[10] = {3.3,56.6,1,7,21,9,6,5,1,8};
	// string arr[arrSize] = {"A","C","D","B"};
	// Student arr[arrSize] = {{"D",90} , {"C",100} , {"B",95} , {"A",95} };
	selectionSort(arr,arrSize);
	SortTestHelper::printArray(arr, arrSize);
	// test();

	int n = 10000;
	int *arra = SortTestHelper::generateRandomArray(n,0,n);
	SortTestHelper::testSort("Selection Sort", selectionSort, arra, n);
	delete[] arra;
	return 0;
}

// select sort, exchange the first elemen for the minimum number 
template<typename T>
void selectionSort(T arr[], int n){
	for(int i = 0; i < n; ++i){
		//寻找 [i, n) 区间最小值
		int minIndex = i;
		for(int j = i + 1; j < n; ++j){
			if(arr[j] < arr[minIndex])
				minIndex = j;					// 最小值索引
		}
		if(i != minIndex){
			swap(arr[i], arr[minIndex]);
		}
	}	
}

void test(){
	string str[5] {"1", "234"};
	for (string& s : str)
		cout << s.size() << " ";
	cout << endl;
}
